package com.smh.a09Clonedemo9;

public class StudentClone implements Cloneable{
    private String name;
    private int age;
    private int[] arr={1,2,3,4,5,6,7};

    public StudentClone() {
    }

    public StudentClone(String name, int age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "Student{name = " + name + ", age = " + age + "}";
    }


    @Override
    public StudentClone clone() {
        try {
            //深克隆
            int [] arr = this.arr;
            int[] newarr = new int[arr.length];
            for (int i = 0; i < newarr.length; i++) {
                newarr[i]=arr[i];
            }
            StudentClone clone = (StudentClone) super.clone();
            clone.arr=newarr;
            // TODO: 复制此处的可变状态，这样此克隆就不能更改初始克隆的内部项
            return clone;
        } catch (CloneNotSupportedException e) {
            throw new AssertionError();
        }
    }

    public int[] getArr() {
        return arr;
    }

    public void setArr(int[] arr) {
        this.arr = arr;
    }
}
